package oddball;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;



public class generateGraph {
	public static void main(String[] args) {
		File file = new File(Config.step1FilePath);
		File output = new File(Config.step2FilePath);
		HashMap<Integer,Double> contextMap = new HashMap<Integer,Double>();
		HashMap<Integer,HashMap<Integer,Integer>> contextNum = new HashMap<Integer,HashMap<Integer,Integer>>();
		HashSet<String> line = new HashSet<String>();
		try {
			BufferedReader br = new BufferedReader(new FileReader(file));
			PrintWriter pw = new PrintWriter(output);
			String li;
			HashMap<Integer,Integer> tmp;
			try {
				while ((li = br.readLine()) != null) {
					String[] sp = li.split("\t");
					int np = Integer.parseInt(sp[0]);
					int context = Integer.parseInt(sp[1]);
					int commonNum = Integer.parseInt(sp[2]);
					double weight = contextMap.get(context);
					tmp = new HashMap<Integer,Integer>();
					tmp = contextNum.get(context);
					double size = tmp.size();
					java.util.Iterator<Entry<Integer, Integer>> iter = tmp.entrySet().iterator();
					while(iter.hasNext()){
						Entry<Integer, Integer> entry = iter.next();
						int np2 = entry.getKey();
						int value = entry.getValue();
						String s = np+"&"+np2;
						if(line.contains(s)){
							continue;
						}
						line.add(s);
						double finalCommon = (commonNum+value)/2;
						double finalWeight = finalCommon *(weight/size);
						pw.println(np+"\t"+np2+"\t"+finalWeight);
						
					}
					
				}
				pw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
